import { BaseEntity, Column, ColumnOptions, CreateDateColumn, JoinColumn, Tree, TreeChildren, TreeLevelColumn, TreeParent, DeleteDateColumn, ManyToOne, OneToMany, OneToOne, Entity as OrmEntity, EntityOptions, PrimaryGeneratedColumn, UpdateDateColumn, Unique } from 'typeorm'
export { Unique, ManyToOne, OneToMany, OneToOne, JoinColumn, Tree, TreeChildren, TreeLevelColumn, TreeParent, Column, BaseEntity }
export { convertFilterParameters, IFilter } from './orm/query.builder'
export const Entity = (options?: EntityOptions & { comment?: string }) => {
    const { comment, ...other } = options;
    return OrmEntity(other)
}
export type IColumn = ColumnOptions & {
    label?: string,
    hide?: boolean,
    fieldProps?: any,
    hideInTable?: boolean,
    valueType?: string,
    valueEnum?: any,
    tooltip?: string
};
export const ShopCardOptionIds = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'jsonb', ...options })
}
export const ShopCardOptionId = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', length: 255, ...options })
}
export const PayType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const PayStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const PayModule = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const IncrementId = (options?: IColumn) => Column({
    type: 'int',
    width: 11,
    generated: 'increment',
    unique: true,
    unsigned: true,
    ...options
})
export const AutoIncrementId = IncrementId;
export const Tags = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 255, ...options })
}
export const SimpleJson = (options?: IColumn) => Column({
    type: 'simple-json',
    ...options
})

export const SimpleArray = (options?: IColumn) => Column({
    type: 'simple-array',
    ...options
})

export const Images = SimpleArray;

export const Username = (options?: IColumn) => Column({
    type: 'varchar',
    width: 30,
    ...options
})

export const Role = (options?: IColumn) => Column({
    type: 'varchar',
    width: 30,
    ...options
})


export const Realname = (options?: IColumn) => Column({
    type: 'varchar',
    width: 30,
    nullable: true,
    ...options
})
export const Title = (options?: IColumn) => Column({
    type: 'varchar',
    width: 120,
    ...options
})

export const Desc = (options?: IColumn) => Column({
    type: 'varchar',
    width: 320,
    ...options
})

export const Address = (options?: IColumn) => Column({
    type: 'varchar',
    width: 255,
    ...options
})
export const Password = (options?: IColumn) => Column({
    type: 'varchar',
    length: 255,
    ...options
})

export const Salt = (options?: IColumn) => Column({
    type: 'varchar',
    length: 32,
    ...options
})


export const Telephone = (options?: IColumn) => Column({
    type: 'varchar',
    length: 320,
    ...options
})


export const Star = (options?: IColumn) => Column({
    type: 'decimal',
    width: 1,
    ...options
})


export const Jsonb = (options?: IColumn) => Column({
    type: 'jsonb',
    ...options
})

export const Link = (options?: IColumn) => Column({
    type: 'varchar',
    width: 320,
    ...options
})

export const Hash = (options?: IColumn) => Column({
    type: 'varchar',
    width: 32,
    ...options
})

export const Boolean = (options?: IColumn) => Column({
    type: 'bool',
    ...options
})

export const Tinyint = (width: number = 1, options?: IColumn) => Column({
    type: 'int2',
    width: width,
    ...options
})

export const Int = (width: number = 8, options?: IColumn) => Column({
    type: 'int4',
    width: width,
    default: 0,
    unsigned: true,
    ...options
})

export const Code = (options?: IColumn & { label?: string }) => Column({
    type: 'varchar',
    width: 100,
    comment: options?.comment || options?.label,
    ...options
})

export const Name = (options?: IColumn & { label?: string }) => Column({
    type: 'varchar',
    width: 100,
    comment: options?.comment || options?.label,
    ...options
})


export const Scope = (options?: IColumn & { label?: string }) => Column({
    type: 'varchar',
    width: 100,
    comment: options?.comment || options?.label,
    ...options
})

export const Country = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '省份', width: 50, ...options })
}
// 省份
export const Province = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '省份', width: 50, ...options })
}
// 城市
export const City = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '城市', width: 50, ...options })
}
// 区域
export const Area = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '区域', width: 50, ...options })
}
export const Latlng = (options: Partial<IColumn> = {}) => {
    return Point({ comment: '经纬度', ...options })
}
// 备注
export const Remark = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '备注', width: 255, ...options })
}
// 富文本
export const RichText = (options: Partial<IColumn> = {}) => {
    return Text({ comment: '富文本', width: 255, ...options })
}
// 性别
export const Gender = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '性别', width: 255, ...options })
}
export const Money = (options: Partial<IColumn> = {}) => {
    return Decimal({ ...options, })
}
export const Price = (options: Partial<IColumn> = {}) => {
    return Decimal({ ...options, })
}
export const Discount = (options: Partial<IColumn> = {}) => {
    return Decimal({ ...options, })
}
export const Point = (options: Partial<IColumn> = {}) => Column({
    type: 'point',
    ...options
})

export const Ip = (options?: IColumn) => Column({
    type: 'varchar',
    length: 30,
    ...options
})
export const Char = (options: Partial<IColumn> = {}) => Column({
    type: 'char',
    ...options
})
export const PrimaryUuid = (options?: IColumn) => PrimaryGeneratedColumn('uuid', options)
export const Uuid = (options?: IColumn) => Column({
    type: 'uuid',
    nullable: true,
    ...options
})
export const CouponType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const DynamicPermission = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'jsonb', ...options })
}
export const CreditType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const WxBannerType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const RolePermission = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'jsonb', ...options })
}
export const TokenStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const SysAttachmentType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const SysAttachmentBucket = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const SysAttachmentFrom = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const ShopOrderStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const ShopGoodOptionType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const ShopGoods = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'jsonb', ...options })
}
export const ShopGoodStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const ShopGoodParams = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'jsonb', ...options })
}
export const ShopGoodUnit = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const ShopGoodType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const ShopCodeStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const SysUserId = Uuid;
export const ShopGoodId = Uuid;
export const WxMGroupId = Uuid;
export const ShopPCategoryId = Uuid;
export const ShopCCategoryId = Uuid;
export const ShopOrderId = Uuid;
export const MemberId = Uuid;
export const CardId = Uuid;
export const CmsCategoryId = Uuid;
export const CreateUserId = Uuid;
export const CoupondCategoryPId = Uuid;
export const CouponLogId = Uuid;
export const CouponId = Uuid;
export const GymTeacherId = Uuid;
export const GymCourseId = Uuid;
export const GymPlaceId = Uuid;
export const GymScheduleId = Uuid;
export const ShopCategoryId = Uuid;
export const CardCategoryId = Uuid;
export const SysUGroupId = Uuid;
export const CardLogId = Uuid;


export const ArrayColumn = SimpleArray;
export const Array = SimpleArray;
export const Date = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'date', ...options })
}
export const DateColumn = Date;

export const AddressDetail = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'jsonb', ...options })
}
export const ShopCartType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const GymAppointmentStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const GymCourseType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const WxCardSchema = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'jsonb', ...options })
}
export const WxCardType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const SysResource = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const WxLoginType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const ShopOrderAction = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const WxVisitScene = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const CardStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const CouponUseLogStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const WxCreditLogOperation = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const CouponLogStatus = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const CouponUseTo = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 255, ...options })
}
export const CouponCanUseTo = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 255, ...options })
}
export const CardUseTo = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 255, ...options })
}
export const CardCanUseTo = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 255, ...options })
}
export const CmsArticleType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const SysTagType = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const CmsArticleAuthor = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 50, ...options })
}
export const PrimaryKey = (options: IColumn = {}) => {
    return Column({ type: 'varchar', width: 100, primary: true, ...options })
}
export const Time = (options: IColumn = {}) => {
    return Column({ type: 'time with time zone', ...options })
}
export const Year = (options: IColumn = {}) => {
    return Column({ type: 'smallint', ...options })
}
export const Week = (options: IColumn = {}) => {
    return Column({ type: 'varchar', length: 10, ...options })
}
export const Day = (options: IColumn = {}) => {
    return Column({ type: 'smallint', ...options })
}
export const Lesson = (options: IColumn = {}) => {
    return Column({ type: 'smallint', ...options })
}
export const Month = (options: IColumn = {}) => {
    return Column({ type: 'smallint', ...options })
}
export const Quarter = (options: IColumn = {}) => {
    return Column({ type: 'smallint', ...options })
}
export const SmallInt = (options: Partial<IColumn> = {}) => Column({
    type: 'smallint',
    ...options
})
export const SmallDigdit = SmallInt;

export const Integer = (options: Partial<IColumn> = {}) => Column({
    type: 'integer',
    default: 0,
    ...options
})

export const Digdit = Integer;
export const DisplayOrder = Integer;
export const BigInt = (options: Partial<IColumn> = {}) => Column({
    type: 'bigint',
    ...options
})

export const Decimal = (options: Partial<IColumn> = {}) => Column({
    type: 'decimal',
    precision: 10,
    scale: 2,
    transformer: {
        from: (val) => {
            return Number(val)
        },
        to: (val) => {
            return val;
        }
    },
    ...options
})
export const Text = (options: Partial<IColumn> = {}) => Column({
    type: 'text',
    ...options
})
export const Varchar = (options: Partial<IColumn> = {}) => Column({
    type: 'varchar',
    ...options
})
export const Color = (options: Partial<IColumn> = {}) => {
    return Varchar({ width: 50, ...options })
}
export const DateTime = (options?: IColumn) => Column({ type: 'timestamp with time zone', nullable: true, ...options })
export const CreateDate = (options?: IColumn) => CreateDateColumn({ type: 'timestamp with time zone', ...options })
export const DeleteDate = (options?: IColumn) => DeleteDateColumn({ type: 'timestamp with time zone', ...options })
export const UpdateDate = (options?: IColumn) => UpdateDateColumn({ type: 'timestamp with time zone', ...options })

export const Mobile = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '手机号', width: 11, ...options })
}
export const Email = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '邮箱', width: 255, ...options })
}
export const Nickname = (options: Partial<IColumn> = {}) => {
    return Varchar({ comment: '姓名', width: 50, ...options })
}
export const Openid = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 100, ...options })
}

export const Image = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 320, nullable: true, default: '', ...options })
}
export const Cover = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 320, nullable: true, default: '', ...options })
}
export const Icon = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 320, nullable: true, default: '', ...options })
}
export const Avatar = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 320, nullable: true, default: '', ...options })
}
export const Logo = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 320, nullable: true, default: '', ...options })
}
export const Audio = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 320, nullable: true, default: '', ...options })
}
export const Video = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 320, nullable: true, default: '', ...options })
}
export const Token = (options: Partial<IColumn> = {}) => {
    return Column({ type: 'varchar', width: 320, ...options })
}